package me.ele.spring.cloud.controller

import me.ele.spring.cloud.FeignApplication
import me.ele.spring.cloud.client.UserClient
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.context.ApplicationContext
import spock.lang.Specification

/**
 *
 * @Auther : 林江 (jiang.lin02@ele.me)
 * @Date :16/9/8 上午10:43
 * @since 1.0
 */
@SpringBootTest(classes = FeignApplication.class ,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = "feign.hystrix.enabled=false")
class ConsumerControllerTest extends Specification {

    @Autowired
    ApplicationContext context

    @Autowired
    ConsumerController consumerController;

    @Autowired
    TestRestTemplate testRestTemplate

    UserClient userClient;


    def setup(){
        userClient =  Mock(UserClient.class);
    }


    def "测试 controller 的add方法是否可以返回正确"() {
        given: "初始化一些参数"
        consumerController.userClient = userClient;

        when:"测试"
        userClient.add(_,_) >> add

        then: "返回的结果"
        testRestTemplate.getForEntity("/add", Integer.class).body == result;

        and:"打印一下"
        println add +" " + result

        where:"结果展示"
        add || result
        1   || 1
        2   || 2
        3   || 3
    }

}
